// import { getAllRoleList, isAccountExist } from '@/api/demo/system';
import { BasicColumn, FormSchema } from '@/components/Table';
import { h } from 'vue';
import { Tooltip } from 'ant-design-vue';
import { getAudiencesListAPI } from '@/api/demo/template';
import { useI18n } from "@/hooks/web/useI18n";

const { t } = useI18n();
async function getAudiencesList() {
  const response = await getAudiencesListAPI();
  return response;
}

export const handleCategoryChange = (value: string) => {
  // 在这里添加你需要的逻辑
};
//表头数据
const Type = [
  {
    label: t('sys.informaionMatchaing.columns.match'),
    value: 'match',
  },
  {
    label: t('sys.informaionMatchaing.columns.orientation'),
    value: 'orientation',
  },
];
const MatchingType = [
  {
    label: t('sys.configuration.notStart'),
    value: t('sys.configuration.notStart'),
  },
  {
    label: t('sys.configuration.inProgress'),
    value: t('sys.configuration.inProgress'),
  },
  {
    label: t('sys.configuration.taskSucces'),
    value: t('sys.configuration.taskSucces'),
  },
  {
    label: t('sys.configuration.taskStop'),
    value: t('sys.configuration.taskStop'),
  },
];
let matchCategory = [];

export const columnsPeopleI: BasicColumn[] = [
  {
    title: 'id',
    dataIndex: 'id',
    width: 50,
  },
  {
    title: t('sys.informaionMatchaing.columns.title'),
    dataIndex: 'title',
    width: 50,
  },
  {
    title: t('sys.configuration.describe'),
    dataIndex: 'content',
    width: 50,
  },
  {
    title:  t('sys.informaionMatchaing.columns.district'),
    dataIndex: 'district',
    width: 50,
  },

  // {
  //   title:  t('sys.informaionMatchaing.columns.age'),
  //   dataIndex: 'age',
  //   width: 50,
  // },
  // {
  //   title:  t('sys.informaionMatchaing.columns.gender'),
  //   dataIndex: 'gender',
  //   width: 50,
  // },
  {
    title:  t('sys.informaionMatchaing.columns.audience'),
    dataIndex: 'audience',
    width: 50,
  },
  {
    title:  t('sys.informaionMatchaing.columns.interest'),
    dataIndex: 'interest',
    width: 50,
  },
  {
    title: t('sys.informaionMatchaing.columns.createTime'),
    dataIndex: 'createTime',
    width: 80,
  },
  {
    title: '匹配状态',
    dataIndex: 'status',
    width: 50,
    customRender: ({ record }: { record: Recordable }) => {
      if (record.status === 0) {
        return t('sys.configuration.notStart');
      } else if (record.status === 1) {
        return '执行中';
      } else {
        return '执行成功';
      }
      return record.status;
    },
  },
  {
    title: t('sys.informaionMatchaing.columns.success'),
    dataIndex: 'success',
    width: 50,
    customRender: ({ record }: { record: Recordable }) => {
      const success = record.success ?? '-';
      const total = record.total ?? '-';
      return `${success}/${total}`;
    },
  },
];

export const columnsModels: BasicColumn[] = [
  {
    title: 'id',
    dataIndex: 'dataId',
    width: 50,
  },
  {
    title: '抖音用户名',
    dataIndex: 'username',
    width: 50,
  },
  {
    title: '抖音账号',
    dataIndex: 'userNo',
    width: 50,
  },
  {
    title: '地址',
    dataIndex: 'address',
    width: 50,
  },
  {
    title: t('sys.comment.columns.comment'),
    dataIndex: 'comment',
    width: 100,
  },
  {
    title: t('sys.informaionMatchaing.columns.url'),
    dataIndex: 'link',
    width: 50,
    customRender: ({ text, record }) => {
      return h(
        'a',
        {
          href: text,
          target: '_blank', // 在新标签页中打开链接
        },
        text,
      );
    },
  },
  {
    title: t('sys.informaionMatchaing.columns.matching'),
    dataIndex: 'matching',
    width: 50,
  },
];
//表头搜素数据
export const searchFormSchema: FormSchema[] = [
  {
    field: 'id',
    label: t('sys.informaionMatchaing.columns.createUsername'),
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'title',
    label: t('sys.informaionMatchaing.columns.title'),
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'status',
    label: t('sys.informaionMatchaing.columns.status'),
    component: 'Select',
    colProps: { span: 4 },
    componentProps: {
      options: MatchingType,
    },
  },
  {
    field: 'type',
    label: t('sys.informaionMatchaing.columns.type'),
    component: 'Select',
    colProps: { span: 4 },
    componentProps: {
      options: Type,
    },
  },
];

// export const searchFormSchemaDtail: FormSchema[] = [
//   {
//     field: 'matching',
//     label: t('sys.informaionMatchaing.columns.matching'),
//     component: 'Input',
//     colProps: { span: 4 },
//     defaultValue: '0.2',
//   },
//   {
//     field: 'customButtons',
//     label: '',
//     component: 'Input', // 这里使用 Input 作为占位符
//     colProps: { span: 4 },
//     render: ({ model, field }) => {
//       return h(
//         'button',
//         {
//           onClick: () => handleButtonClick(model, field),
//         },
//         '按钮',
//       );
//     },
//   },
// ];

export const accountFormSchema: FormSchema[] = [
  {
    field: 'title',
    component: 'Input',
    label: t('sys.informaionMatchaing.columns.title'),
    defaultValue: '',
    colProps: {
      span: 24,
    },
    rules: [{ required: true }],
  },
  {
    field: 'remark',
    component: 'InputTextArea',
    label: t('sys.configuration.describe'),
    defaultValue: '',
    colProps: {
      span: 24,
    },
    componentProps: {
      rows: 3, // 设置文本域的行数
    },
    rules: [{ required: true }],
  },
  {
    field: 'category',
    component: 'AutoComplete',
    label: t('sys.informaionMatchaing.columns.category'),
    defaultValue: '',
    colProps: {
      span: 24,
    },
    componentProps: {
      options: MatchingType,
      filterOption: (inputValue, option) => {
        return option.value.toUpperCase().indexOf(inputValue.toUpperCase()) !== -1;
      },
    },
    rules: [{ required: true }],
  },
  {
    field: 'date',
    component: 'DatePicker',
    label: t('sys.informaionMatchaing.columns.DatePicker'),
    defaultValue: '',
    colProps: {
      span: 24,
    },
    componentProps: {
      format: 'YYYY-MM-DD HH:mm:ss', // 设置显示格式
      showTime: true, // 显示时间选择器
      valueFormat: 'YYYY-MM-DD HH:mm:ss', // 设置返回值的格式
    },
    rules: [{ required: true }],
  },
];
//人员匹配
export const accountFormSchemPeople: FormSchema[] = [
  {
    field: 'templateId',
    component: 'ApiSelect',
    label: '广告受众模板',
    defaultValue: '',
    colProps: {
      span: 24,
    },
    componentProps: {
      api: getAudiencesListAPI, // 指定接口函数
      resultField: 'data', // 接口返回的数据字段名
      labelField: 'remark', // 选项显示的标签字段名
      valueField: 'id', // 选项的值字段名
      placeholder: '请选择模板', // 添加提示文本
      onChange: (value) => {
        // 触发 fetchTemplateDetail 方法
        fetchTemplateDetail(value);
      },
    },
  },
  {
    field: 'title',
    component: 'Input',
    label: t('sys.informaionMatchaing.columns.title'),
    defaultValue: '',
    colProps: {
      span: 24,
    },
    rules: [{ required: true }],
  },
  {
    field: 'content',
    component: 'InputTextArea',
    label: t('sys.configuration.describe'),
    defaultValue: '',
    colProps: {
      span: 24,
    },
    componentProps: {
      rows: 3, // 设置文本域的行数
    },
    rules: [{ required: true }],
  },
  {
    field: 'district',
    component: 'Input',
    label:  t('sys.informaionMatchaing.columns.district'),
    defaultValue: '',
    rules: [{ required: true }],
  },

  // {
  //   field: 'age',
  //   component: 'Input',
  //   label:  t('sys.informaionMatchaing.columns.age'),
  //   defaultValue: '',
  //   rules: [{ required: true }],
  // },
  // {
  //   field: 'gender',
  //   component: 'Input',
  //   label:  t('sys.informaionMatchaing.columns.gender'),
  //   defaultValue: '',
  //   rules: [{ required: true }],
  // },
  {
    field: 'audience',
    component: 'Input',
    label:  t('sys.informaionMatchaing.columns.audience'),
    defaultValue: '',
    rules: [{ required: true }],
  },
  {
    field: 'interest',
    component: 'InputTextArea',
    label:  t('sys.informaionMatchaing.columns.interest'),
    defaultValue: '',
    componentProps: {
      rows: 3, // 设置文本域的行数
    },
    rules: [{ required: true }],
  },
];

//定向匹配
export const accountFormSchemapositon: FormSchema[] = [
  {
    field: 'title',
    component: 'Input',
    label: t('sys.informaionMatchaing.columns.title'),
    defaultValue: '',
    colProps: {
      span: 24,
    },
    rules: [{ required: true }],
  },
  {
    field: 'remark',
    component: 'InputTextArea',
    label: t('sys.configuration.describe'),
    defaultValue: '',
    colProps: {
      span: 24,
    },
    componentProps: {
      rows: 3, // 设置文本域的行数
    },
    rules: [{ required: true }],
  },

  // {
  //   field: 'type',
  //   component: 'Input',
  //   label: t('sys.informaionMatchaing.columns.type'),
  //   defaultValue: '',
  //   colProps: {
  //     span: 24,
  //   },
  //   rules: [{ required: true }],
  // },
  // {
  //   field: 'status',
  //   component: 'Select',
  //   label: '匹配状态',
  //   defaultValue: '',
  //   colProps: {
  //     span: 24,
  //   },
  //   componentProps: {
  //     options: MatchingType,
  //   },
  //   rules: [{ required: true }],
  // },
  {
    field: 'category',
    component: 'AutoComplete',
    label: t('sys.informaionMatchaing.columns.category'),
    defaultValue: '',
    colProps: {
      span: 24,
    },
    componentProps: {
      options: MatchingType,
      filterOption: (inputValue, option) => {
        return option.value.toUpperCase().indexOf(inputValue.toUpperCase()) !== -1;
      },
      onChange: (value) => {
        // 这里是你想要执行的方法
        handleCategoryChange(value);
      },
    },
    rules: [{ required: true }],
  },
  {
    field: 'date',
    component: 'DatePicker',
    label: t('sys.informaionMatchaing.columns.DatePicker'),
    defaultValue: '',
    colProps: {
      span: 24,
    },
    componentProps: {
      format: 'YYYY-MM-DD HH:mm:ss', // 设置显示格式
      showTime: true, // 显示时间选择器
      valueFormat: 'YYYY-MM-DD HH:mm:ss', // 设置返回值的格式
    },
    rules: [{ required: true }],
  },
  {
    field: 'maxNum',
    component: 'Input',
    label: t('sys.orientation.maxNum'),
    /**!!!renderColContent 没有FormItem 包裹, 若想要 Form 提交需要带上数据须 <FormItem name={}></FormItem> 包裹： 示例如下*/
    colProps: {
      span: 24,
    },
    rules: [{ required: true }],
  },
  {
    field: 'maxNode',
    component: 'Input',
    label: t('sys.orientation.maxNode'),
    /**!!!renderColContent 没有FormItem 包裹, 若想要 Form 提交需要带上数据须 <FormItem name={}></FormItem> 包裹： 示例如下*/
    colProps: {
      span: 24,
    },
    rules: [{ required: true }],
  },
  {
    field: 'target',
    component: 'Input',
    label: '目标人群',
    /**!!!renderColContent 没有FormItem 包裹, 若想要 Form 提交需要带上数据须 <FormItem name={}></FormItem> 包裹： 示例如下*/
    colProps: {
      span: 24,
    },
    rules: [{ required: true }],
  },
  // {
  //   field: 'keywordValue',
  //   component: 'Input',
  //   label: t('sys.orientation.keyword'),
  //   /**!!!renderColContent 没有FormItem 包裹, 若想要 Form 提交需要带上数据须 <FormItem name={}></FormItem> 包裹： 示例如下*/
  //   colSlot: 'colSlot_field5',
  //   colProps: {
  //     span: 12,
  //   },
  //   dynamicDisabled: ({ values }) => {
  //     return !!values.field_disabled;
  //   },
  // },
];
